// 2. redis dcs
data "huaweicloud_dcs_flavors" "single_flavors" {
  cache_mode = var.dcs_cache_mode
  capacity   = var.dcs_capacity
}

resource "huaweicloud_dcs_instance" "this" {
  count = var.dcs_create ? 1 : 0

  name           = var.dcs_name
  engine         = var.dcs_engine
  engine_version = var.dcs_engine_version
  capacity       = data.huaweicloud_dcs_flavors.single_flavors.capacity
  flavor         = data.huaweicloud_dcs_flavors.single_flavors.flavors[0].name

  availability_zones = [
    data.huaweicloud_dcs_flavors.single_flavors.flavors[0].available_zones.0
  ]

  vpc_id        = huaweicloud_vpc.this.id
  subnet_id     = huaweicloud_vpc_subnet.this.0.id
  password      = var.dcs_password
  charging_mode = "postPaid"

  #  whitelists {
  #    group_name = "test-group1"
  #    ip_address = ["192.168.10.100", "192.168.0.0/24"]
  #  }

  #  dynamic "whitelists" {
  #    for_each       = var.dcs_whitelists
  #    content {
  #      group_name = lookup(whitelists.value, "group_name")
  #      ip_address = lookup(whitelists.value, "ip_address")
  #    }
  #  }

  description           = var.dcs_description
  #enterprise_project_id = var.enterprise_project_id
  depends_on = [huaweicloud_vpc_subnet.this]
}
